<template>
  <div class="calendar-bottom">
    <div class="left">
      <h2>{{ result.lunar }}</h2>
      <h3>{{ result.lunarYear }} {{ result.animalsYear }}年</h3>
    </div>
    <div class="right">
        <div class="green">宜:<span>{{ result.suit }}</span></div>
        <div class="red">忌:<span>{{ result.avoid }}</span></div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted,watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useCalendarStore } from '@/stores/calendar.js'
import axios from 'axios'

const { formatDate } = storeToRefs(useCalendarStore())
// 定义 API 密钥
const key='e3c654f274663b03b8eed73aeecdb729'

const result=ref({
    lunar:'',
    lunarYear:'',
    animalsYear:'',
    suit:'',
    avoid:''
})

const getInfo=async()=>{
    const res=await axios.get(`/calendar/day?date=${formatDate.value}&key=${key}`)
    result.value=res.data.result.data
}
// 侦听formatDate变化
watch(formatDate,()=>{
    getInfo()
})
// 在组件挂载后首次加载数据。组件内容显示到页面上后，自动执行指定的代码。
onMounted(()=>{
    getInfo()
})
</script>

<style lang="scss" scoped>
.calendar-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 16px;
  .left {
    flex: 1;
  }
  .right {
    flex: 3;
    span {
      font-size: 14px;
    }
    .green{
        color: rgb(46, 192, 6);
    }
    .red{
        color: rgb(218, 4, 4);
    }
  }
}
</style>
